package com.baijiaoxi.common.utils.jdk;


import org.apache.logging.log4j.util.PropertiesUtil;

public class Strings {
    public static final String EMPTY = "";
    public static final String LINE_SEPARATOR = PropertiesUtil.getProperties().getStringProperty("line.separator", "\n");


    public static String nullToDefault(String value, String defaultStr) {
        return value == null ? defaultStr : value;
    }

    public static String blankToDefault(String value, String defaultStr) {
        return isNullOrEmpty(value) ? defaultStr : value;
    }

    public static String nullToEmpty(String string) {
        return com.google.common.base.Strings.nullToEmpty(string);
    }


    public static String emptyToNull(String string) {
        return com.google.common.base.Strings.emptyToNull(string);
    }


    public static boolean isNullOrEmpty(String string) {
        return com.google.common.base.Strings.isNullOrEmpty(string);
    }


    public static String padStart(String string, int minLength, char padChar) {
        return com.google.common.base.Strings.padStart(string, minLength, padChar);
    }


    public static String padEnd(String string, int minLength, char padChar) {
        return com.google.common.base.Strings.padEnd(string, minLength, padChar);
    }


    public static String repeat(String string, int count) {
        return com.google.common.base.Strings.repeat(string, count);
    }


    public static String commonPrefix(CharSequence a, CharSequence b) {
        return com.google.common.base.Strings.commonPrefix(a, b);
    }


    public static String commonSuffix(CharSequence a, CharSequence b) {
        return com.google.common.base.Strings.commonSuffix(a, b);
    }

    public static String lenientFormat(
            String template, Object... args) {
        return com.google.common.base.Strings.lenientFormat(template, args);
    }

    public static boolean isBlank(String s) {
        if (s == null || s.isEmpty()) {
            return true;
        }
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (!Character.isWhitespace(c)) {
                return false;
            }
        }
        return true;
    }

    public static boolean isNotBlank(String string) {
        return !isBlank(string);
    }

}
